<template>
  <a-card :bordered="false" class="card-area">
      <a-form :form="form" >
        <a-form-item label="token过期时长(秒)" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
        <a-input v-decorator="['tokenExpire', { rules: [{ required: true, message: '请输入过期时长!' }] }]" />
        </a-form-item>
        <a-form-item label="token存储位置" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
        <a-select v-decorator="['tokenLocation', { rules: [{ required: true, message: '请输入存储位置!' }] },]"
            placeholder="选择存储位置">
            <a-select-option value="sql">
            数据库
            </a-select-option>
            <a-select-option value="redis">
            redis
            </a-select-option>
        </a-select>
        </a-form-item>
        <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
        <a-button type="primary" @click="handleSubmit">
            确定
        </a-button>
        </a-form-item>
    </a-form>
  </a-card>
</template>

<script>
import { getAction, httpAction,postAction } from '@/api/manage'

  export default {
    name: "Config",
    components: {
    },
    data () {
      return {
          form:this.$form.createForm(this),
          oriForm:{}
      }
    },
    computed: {
         
    },
    created(){
        getAction("/config/get").then((res) => {
            if(res.success){
                this.oriForm=res.data
                this.form.setFieldsValue({tokenLocation:res.data.tokenLocation,tokenExpire:res.data.tokenExpire})
            }
         })
    },
    methods: {
        handleSubmit(){
            this.form.validateFields((err, values) => {
            if (!err) {
                this.oriForm.tokenLocation=values.tokenLocation
                this.oriForm.tokenExpire=values.tokenExpire
                postAction("/config/edit",this.oriForm).then(r=>{
                    this.$message.success(r.msg)
                })
            }})
        }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>